<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="layui/css/layui.css">
<script type="text/javascript" src="layui/layui.js"></script>
</head>
<body>
	<div id="my_div" style="display: none;">
		<form lay-filter="f_m" id="my_fm" class="layui-form" action="">
			<input name="AskerId" type="hidden">
			 <div class="layui-form-item">
			    <label class="layui-form-label">名字</label>
			    <div class="layui-input-block">
			      <input type="text" disabled name="AskerName" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
			    </div>
			 </div>
			 <div class="layui-form-item">
			    <label class="layui-form-label">权重</label>
			    <div class="layui-input-block">
			      <input type="text" name="Weight" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
			    </div>
			 </div>
			 <div class="layui-form-item">
			    <label class="layui-form-label">备注信息</label>
			    <div class="layui-input-block">
			      <input type="text" name="BakContent" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
			    </div>
			 </div>
			 
			 <div class="layui-form-item">
			    <div class="layui-input-block">
			      <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即修改</button>
			    </div>
			 </div>
		</form>
	</div>
	<table id="demo" lay-filter="test"></table>
	<script type="text/html" id="barDemo">
  		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	</script>
	<script>
		layui.use(['table','layer','form'], function(){
		  var table = layui.table;
		  var layer = layui.layer;
		  var form = layui.form;
		  var $ = layui.$;
		  
		  //第一个实例
		  table.render({
		    elem: '#demo'
		    ,id:'myTab'
		    ,url: 'getAsker' //数据接口
		    ,page: true //开启分页
		    ,cols: [[ //表头
		      {field: 'AskerName', title: '咨询师名称'}
		      ,{field: 'CheckState', title: '签到状态'}
		      ,{field: 'CheckInTime', title: '签到时间'} 
		      ,{field: 'ChangeState', title: '是否分配学生'}
		      ,{field: 'Weight', title: '权重'}
		      ,{field: 'RoleName', title: '角色名称'}
		      ,{field: 'BakContent', title: '备注信息'}
		       ,{fixed: 'right', width:150, align:'center', toolbar: '#barDemo'} //这里的toolbar值是模板元素的选择器
		    ]]
		  });
		  //工具条事件
			table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
			  var data = obj.data; //获得当前行数据
			  var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
			  var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
			 
			  if(layEvent === 'edit'){ //查看
			  	form.val('f_m',data);
			  	layer.open({
			  		type:1,
			  		content:$("#my_div"),
			  		area:['500px','500px']
			  	});
			  } 
			});
			form.on('submit(demo1)', function(data){
			  $.post("xgWeight",$("#my_fm").serialize(),function(res){
			  	if(res.code=="0"){
			  		layer.closeAll();
			  		layer.msg(res.msg);
			  		table.reload('myTab');
			  	}else{
			  		layer.msg(res.msg);
			  	}
			  },"json");
			  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
		});
	</script>
</body>
</html>